//
//  HSWebsiteViewController.swift
//  HomeSchoolDemo
//
//  Created by rimi on 16/9/29.
//  Copyright © 2016年 黄华强. All rights reserved.
//

import UIKit
import WebKit

class HSWebsiteViewController: UIViewController,WKNavigationDelegate,WKUIDelegate {

    let activityView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.whiteLarge)
    var webUrl: String = ""
    override func viewDidLoad() {
        super.viewDidLoad()
        
        loadWebView()
        setupNavi()
        activityView.center = view.center
        activityView.color = #colorLiteral(red: 0.1019607857, green: 0.2784313858, blue: 0.400000006, alpha: 1)
        view.addSubview(activityView)
        
    }
    
        
    func setupNavi() {
        let backBtn = UIBarButtonItem(title: "返回", style: .plain, target: self, action: #selector(backBtnClicked))
        print(navigationItem)
        navigationItem.leftBarButtonItems = [backBtn]
    }
    
    func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
        activityView.startAnimating()
    }
    
    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
        activityView.stopAnimating()
    }
    
    func backBtnClicked() {
        dismiss(animated: true, completion: nil)
    }

    func loadWebView() {
        let webView = WKWebView(frame: view.bounds)
        webView.navigationDelegate = self
        webView.uiDelegate = self
        view.addSubview(webView)
        
        webUrl = "https://" + webUrl
        print(webUrl)
        webView.load(NSURLRequest(url: URL(string: webUrl)!) as URLRequest)

    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    


}
